
var loginBtn = document.querySelector('header .member > div')
loginBtn.onclick = function() {
    var loginDialog = document.querySelector('section.login')
    loginDialog.style.visibility = 'visible'
}
var loginCloseBtn = document.querySelector('section.login i.icon-close')
loginCloseBtn.onclick = function() {
    var loginDialog = document.querySelector('section.login')
    loginDialog.style.visibility = 'hidden'
}

var loginBlueBox = document.querySelector('section.login .menu')
loginBlueBox.onmousedown = function(evt) 
{
    var oldE = evt || window.event
    document.onmousemove = function(evt) 
    {
        var e = evt || window.event
        var left = e.clientX - oldE.offsetX
        var top = e.clientY - oldE.offsetY
        if (left<0) left = 0
        if (top<0) top = 0
        var loginDialog = document.querySelector('section.login .item')
        var maxLeft = (window.innerWidth || document.documentElement.clientWidth) - loginDialog.offsetWidth
        var maxTop = (window.innerHeight || document.documentElement.clientHeight) - loginDialog.offsetHeight
        if (left > maxLeft) left = maxLeft
        if (top > maxTop) top = maxTop
        loginDialog.style.position = 'absolute'
        loginDialog.style.left = left + 'px'
        loginDialog.style.top = top + 'px'
    }
    document.onmouseup = function() {
        document.onmousemove = null
    }
}


var num = 5
var loginCaptchaBtn = document.querySelector('section.login .captcha')
loginCaptchaBtn.onclick = function() {
    var captchaObj = document.querySelector('section.captcha')
    captchaObj.style.visibility = 'visible'
    document.querySelector('section.captcha i.icon-close').onclick = function() {
        captchaObj.style.visibility = 'hidden'
    }

    var dragBtn = captchaObj.querySelector('.drag .btn')
    dragBtn.onmousedown = function() {
        document.onmousemove = function(evt) {
            var e = evt || window.event
            var left = e.clientX - (captchaObj.offsetLeft - captchaObj.offsetWidth/2) - dragBtn.offsetWidth
            dragBtn.style.left = left + 'px'
            captchaObj.querySelector('.check img:nth-of-type(2)').style.left = left + 'px'
        }
        document.onmouseup = function() {
            document.onmousemove = null
            var value = parseInt(dragBtn.style.left)
            if (value >= 260 && value<=265)
            {
                captchaObj.style.visibility = 'hidden'
                loginCaptchaBtn.innerText = num+'秒后重发'
                loginCaptchaBtn.disabled =  true
                t = setInterval(function() {
                    if (num<=1) {
                        clearInterval(t)
                        loginCaptchaBtn.innerText = '重新发送'
                        num = 5
                        loginCaptchaBtn.disabled =  false
                        return
                    }
                    num--
                    loginCaptchaBtn.innerText = num+'秒后重发'
                }, 1000)

            }
            dragBtn.style.left =  '0px'
            captchaObj.querySelector('.check img:nth-of-type(2)').style.left =  '0px'
        }
    }
    return

}